<?php
  class user
  {
	  public $db;
	  public $user;
	  public $userID;
	  
	  public function __construct($db)
	  {
		if(is_object($db))
		{
			$this->db = $db;
		}
		else
		{
			die('User Class __construct Need $db object (d3sql Class).');
		}
	  }
	  
	  /**
	  * set User to Class.  $user is Allready return this user detail. 
	  * 
	  * @param mixed $userID
	  */
	  public function setUser($userID)
	  {
		$userDetailSQLText = "SELECT * FROM snm_users WHERE id =".intval($userID);
		$userDetailSQL = $this->db->sql($userDetailSQLText);
		if($this->db->say($userDetailSQL) > 0)
		{
			$this->user = $this->db->getir($userDetailSQL);
			$this->userID = $userID;
			return true;
		}
		else
		{
			$this->user = null;
			return false;
		}
	  }
	  
	  /**
	  * return User Details
	  * 
	  * @param mixed $userID
	  */
	  public function getUserDetail($userID)
	  {
		 $userDetailSQLText = "SELECT * FROM snm_users WHERE id =".intval($userID);
		 $userDetailSQL = $this->db->sql($userDetailSQLText);
		 if($this->db->say($userDetailSQL) > 0)
		 {
			 $user = $this->db->getir($userDetailSQL);
		 }
		 else
		 {
			 $user = null;
		 }
		 
		 return $user;
	  }
	  
	  /**
	  * Get User List
	  * 
	  */
	  public function getUserList()
	  {
			$userListSQLText = "SELECT u.* , ( SELECT user_name FROM snm_users su WHERE su.id=u.constituent ) as constituent, ( SELECT group_name FROM snm_group WHERE id=u.authority_group_id) as group_name FROM snm_users u ORDER BY u.user_name ASC";
			$userListSQL = $this->db->sql($userListSQLText);
			$users = array();
			if($this->db->say($userListSQL) > 0)
			{
				while($user = $this->db->getir($userListSQL))
				{
					$users[] = $user;
				}
			}
			else
			{
				$users = null;
			}
		 
			return $users;
	  }
	  
  }
?>
